package com.ichir.projects.uiflow.internal.resolvers;

import com.ichir.projects.uiflow.definition.IFlowDefinition;
import com.ichir.projects.uiflow.definition.IFlowPart;
import com.ichir.projects.uiflow.internal.api.IFlowResolver;
import com.ichir.projects.uiflow.ui.api.IUiPart;

/**
 * {@link IFlowResolver} default implementation.
 * 
 * @author mahieddine_ichir
 */
public class FlowActionResolver implements IFlowResolver {

	@Override
	public IFlowPart resolveFlowPart(IFlowDefinition flowDefinition, IUiPart uiPart) {
		if (flowDefinition.getActions() == null) {
			return null;
		}
		for (IFlowPart flowPart : flowDefinition.getActions()) {
			if (flowPart.getUiPartClassname().equals(uiPart.getClass())) {
				return flowPart;
			}
		}
		return null;
	}

	@Override
	public IFlowPart getFlowPartById(IFlowDefinition flowDefinition, String flowPartId) {
		if (flowDefinition.getActions() == null) {
			return null;
		}
		for (IFlowPart flowPart : flowDefinition.getActions()) {
			if (flowPart.getId().equals(flowPartId)) {
				return flowPart;
			}
		}
		return null;
	}
}
